package cn.dnui_yxk801.dnuifood_16110100801.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.dnui_yxk801.dnuifood_16110100801.R;
import cn.dnui_yxk801.dnuifood_16110100801.bean.CommentsBean;
import cn.dnui_yxk801.dnuifood_16110100801.bean.FoodBean;
import cn.dnui_yxk801.dnuifood_16110100801.controller.ModifyCommentsActivity;
import cn.dnui_yxk801.dnuifood_16110100801.listener.OnRetrofitListener;

public class OrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private String content;
    private String item_id;
    private List<CommentsBean> datalist;
    private LayoutInflater layoutInflater;
    private static String Baseurl="http://172.24.10.175:8080/foodService/";

    public OrderAdapter(Context context,List datalist){
        this.context=context;
        this.datalist=datalist;
        layoutInflater=LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v=layoutInflater.from(viewGroup.getContext()).inflate(R.layout.orderitem,viewGroup,false);
        return new OrderAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int i) {
        CommentsBean entity=(CommentsBean)datalist.get(i);
        if (entity==null)
            return;
        OrderAdapter.ViewHolder viewHolder=(OrderAdapter.ViewHolder)holder;
        item_id=entity.getItem_id();
        //content=entity.getContent();
        viewHolder.shopname.setText(entity.getShopname());
        viewHolder.foodname.setText(entity.getFoodname());
        viewHolder.time.setText(entity.getOrder_time());
        viewHolder.sum.setText(entity.getSum());
        viewHolder.comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, ModifyCommentsActivity.class);
                int flag=1;
                intent.putExtra("item_id",item_id);
                intent.putExtra("flag",flag);
                //intent.putExtra("content",content);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datalist.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView foodname, sum,shopname,time;
        Button comment;


        public ViewHolder(View view) {
            super(view);
            foodname = (TextView) view.findViewById(R.id.order_tv_foodname);
            sum = (TextView) view.findViewById(R.id.order_tv_sum);
            time = (TextView) view.findViewById(R.id.order_tv_time);
            shopname=(TextView)view.findViewById(R.id.order_tv_shopname);
            comment=(Button)view.findViewById(R.id.order_btn_comment);

        }
    }
}
